package game;

import javax.swing.JOptionPane;

public class Tax extends Field {

	private int tax;
	private int forcedChoice = 0;

	public Tax(String name, int tax){
		this.name = name;
		this.tax = tax;
	}

	public void setForcedChoice(int choice)
	{
		forcedChoice = choice;
	}

	public void landOnField(Player player){
		int account = player.getAccount().getPoint();

		if (name == "Indkomstskat") {

			Object[] possibleChoices = {"Betal 10%", "Betal 4000"};
			int choice;
			if ((forcedChoice == 0) || (forcedChoice == 1))
			{
				choice = forcedChoice;
			}
			else
			{
				choice = JOptionPane.showOptionDialog(null, player.getName() + " det er din tur!\nHvad vil du gøre ?\n", player.getName(), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, possibleChoices, possibleChoices[0]);
			}

			if (choice == 0) { //Dette valg er 10%
				int ownedProperties = 0;
				int ownedAmount = 0;

				for (int i = 0; i < Board.fields.length; i++){
					if (Board.fields[i] instanceof Ownable){
						Ownable fieldAsOwnable = (Ownable) Board.fields[i]; 

						if(fieldAsOwnable.getOwner() == player) {
							ownedAmount = ownedAmount + fieldAsOwnable.getPrice();

							if(fieldAsOwnable instanceof Street) {
								Street fieldAsStreet = (Street) fieldAsOwnable;
								ownedProperties = ownedProperties + fieldAsStreet.getProperty();
								ownedAmount = ownedAmount + fieldAsStreet.getPropertyPrice();
							}
						}
					}
				}

				tax = (account + ownedAmount) / 10;
				player.getAccount().addPoints(-tax);

			} else {  //Dette er 4000 kr
				player.getAccount().addPoints(-4000);

			}

		} else { //Hvis lander på Extraordinær Statsskat

			player.getAccount().addPoints(-tax);

		}
	}
}